$(document).ready(function() {

});


$(document).on('click', '#add-btn', function() {

    var $noticeTitle=$("input[name='noticeTitle']").val();
    var $noticeAuthor=$("#select2 option:selected").val();
    var $noticeContent=html_encode(tinyMCE.activeEditor.getContent());

    //封装成对象提交
    var data = {
        teInfoId:1,
        noticeTitle:$noticeTitle,
        noticeContent:$noticeContent,
        noticeAuthor:$noticeAuthor,
        noticeDatetime:new Date()
    }
    $.ajax({
        url: "http://localhost:8080/notice/addNotice",
        type: "POST",
        async: false,
        data:JSON.stringify(data),
        dataType: "json",
        contentType:"application/json",
        success:function () {

            layer.confirm('添加成功!继续添加？',{
                btn:['确认','取消']
            },function () {
                layer.msg("请继续添加！")
            },function () {
                location.href='noticeManger.html';
            })

        },
        error:function () {
            layer.alert("你的网络太慢了！添加失败!再试一次吧！");
        }
    });
});


/*html转码*/
function html_encode(str) {
    var s = "";
    if (str.length == 0)
        return "";
    s = str.replace(/&/g, "&gt;");
    s = s.replace(/</g, "&lt;");
    s = s.replace(/>/g, "&gt;");
    s = s.replace(/ /g, "&nbsp;");
    s = s.replace(/\'/g, "&#39;");
    s = s.replace(/\"/g, "&quot;");
    s = s.replace(/\n/g, "<br>");
    return s;
}

